<template>
  <div>
    <h1>欢迎:{{ username }}</h1>
    <h1>个性签名:{{ sign }}</h1>
    <p>
      <van-field label="标题" v-model="form.title"></van-field>
    </p>
    <p>
      <van-field label="内容" v-model="form.content" type="textarea"></van-field>
    </p>
    <van-button @click="add" round>添加</van-button>
    <h1>展示文章</h1>
    <table>
      <van-button @click="changeuid">我的文章</van-button>
      <tr>
        <td>id</td>
        <td>标题</td>
        <td>内容</td>
      </tr>
      <tr v-for="i in list">
        <td>{{ i.id }}</td>
        <td>{{ i.title }}</td>
        <td>{{ i.content }}</td>
      </tr>
    </table>

  </div>
</template>

<script>
export default {
  name: "ainfo",
  data() {
    return {
      username: localStorage.getItem('username'),
      sign: localStorage.getItem('sign'),
      form: {'userid': localStorage.getItem('userid')},
      uid: 0,
      list: []
    }
  },
  methods: {
    add() {
      this.$axios.post('/info/rticle', this.form)
        .then(res => {
          if (res.data.code == 200) {
            alert('添加成功')
            this.form = {'userid': localStorage.getItem('userid')}
          }
        })
    },
    get_rticle() {
      this.$axios.get('/info/rticle?userid=' + this.uid)
        .then(res => {
          this.list = res.data.list
        })

    },
    changeuid() {
      this.uid = this.form.userid
      this.get_rticle()
    }
  },
  mounted() {
    this.get_rticle()
  }
}
</script>

<style scoped>

</style>
